// import { queryOwnGroup } from '@/api'
import * as types from '../mutation-types'

// 初始 state
const state = {
  uid: '',          // 企业联系人 ID     --|
  enterId: '',      // 企业 ID             |
  employeeName: '', // 当前用户员工名字    |
  companyName: '',  // 公司名字            |=> 通过调和飞信 API 取得
  phone: '',        // 员工手机号          |
  email: '',        // 员工邮件账号      --|

  employeeId: '',   // 当前用户员工 ID  --|
  attendanceId: '', // 考勤组 ID          |=> 通过调用中间件接口取得
  attendanceName: ''// 考勤组名字       --|
}

// getters
const getters = {
  getUid: state => state.uid,
  getEmployeeId: state => state.employeeId,
  getEnterId: state => state.enterId,
  getAttendanceId: state => state.attendanceId,
  getEmployeeName: state => state.employeeName,
  getAttendanceName: state => state.attendanceName,
  getPhone: state => state.phone,
  getEmail: state => state.email,
  getCompanyName: state => state.companyName
}

// actions
const actions = {
  fetchUserOwnInfo ({ commit, state }, data) {
    if (!state.attendanceId) {
      let _var = data

      let employeeId = _var && _var.employeeId
      let attendanceId = _var && _var.attendanceId
      let attendanceName = _var && _var.attendanceName
      commit(types.INIT_USER_OWN_DATA, { employeeId, attendanceId, attendanceName })
    }
  },
  fetchUserEnterInfo ({ commit, state }, data) {
    let uid = data.id
    let enterId = data.enterpriseId
    let employeeName = data.name
    let companyName = data.company
    let phone = data.phone
    let email = data.email
    commit(types.INIT_USER_ENTER_DATA, { uid, enterId, employeeName, companyName, phone, email })
  }
}

// mutations
const mutations = {
  [types.INIT_USER_OWN_DATA] (state, { employeeId, attendanceId, attendanceName }) {
    state.employeeId = employeeId
    state.attendanceId = attendanceId
    state.attendanceName = attendanceName
  },
  [types.INIT_USER_ENTER_DATA] (state, { uid, enterId, employeeName, companyName, phone, email }) {
    state.uid = uid
    state.enterId = enterId
    state.employeeName = employeeName
    state.companyName = companyName
    state.phone = phone
    state.email = email
  }
}

// export utils
export default {
  state,
  getters,
  actions,
  mutations
}
